<template>
  <view class="tab-bar-component">
    <view class="tab-box">
      <view
        class="tab-item"
        :class="activeComponentName == item.componentName ? 'active' : ''"
        v-for="(item, index) in tabBarList"
        :key="index"
        @click="toPage(item)"
      >
        <text class="iconfont" :class="item.icon"></text>
        <text class="title">{{ item.title }}</text>
      </view>
    </view>
  </view>
</template>

<script>
import { defineComponent, reactive, toRefs } from "vue";
export default defineComponent({
  name: "",
  props: {},
  components: {},
  setup(props, ctx) {
    const data = reactive({
      activeComponentName: "componentsIndex",
      tabBarList: [
        {
          title: "组件",
          icon: "icon-weibiaoti--42",
          componentName: "componentsIndex",
        },
        {
          title: "页面",
          icon: "icon-weibiaoti--41",
          componentName: "appPageIndex",
        },
      ],
    });
    const toPage = (item) => {
      data.activeComponentName = item.componentName;
      ctx.emit("changeComponent", item.componentName);
    };
    return {
      toPage,
      ...toRefs(data),
    };
  },
});
</script>

<style scoped lang="less">
.tab-bar-component {
  position: fixed;
  bottom: 0;
  left: 0;
  z-index: 99;
  display: flex;
  width: 100%;
  justify-content: space-between;
  height: 80rpx;
  background: #fff;
  box-shadow: 0 0 1rpx 1rpx rgba(0, 0, 0, 0.1);
  .tab-box {
    flex: 1;
    display: flex;
    flex-direction: row;
    justify-content: space-around;
    .tab-item {
      flex: 1;
      display: flex;
      flex-direction: column;
      justify-content: center;
      align-items: center;
      position: relative;
      .iconfont {
        font-size: 40rpx;
      }
      .title {
        margin-top: 10rpx;
        font-size: 20rpx;
        font-weight: 300;
      }
      &.active {
        .iconfont,
        .title {
          color: #006eff;
        }
      }
    }
  }
}
</style>
